﻿using BLL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace HotelCode.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        public UserBLL UserBLL { get; }
        public ILogger<UserController> Logger { get; }

        public UserController(UserBLL userBLL, ILogger<UserController> logger)
        {
            UserBLL = userBLL;
            Logger = logger;
        }
        [HttpPost]
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public IActionResult UserAdd(UserModel info)
        {
            try
            {
                int res = UserBLL.UserAdd(info);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpGet]
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="UserPwd"></param>
        /// <returns></returns>
        public IActionResult Login(string UserName, string UserPwd)
        {
            try
            {
                Logger.LogInformation($"用户{UserName}登录成功");
                int res = UserBLL.Login(UserName, UserPwd);
                return Ok(res);
            }
            catch (Exception)
            {

                Logger.LogError($"用户{UserName}登录失败");
                throw;
            }
        }
    }
}
